package com.qg.wcsopcuaqj.business.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qg.wcsopcuaqj.business.entity.TWcsRgvAlarm;
import com.qg.wcsopcuaqj.business.entity.TWcsTask;
import com.qg.wcsopcuaqj.business.mapper.TWcsRgvAlarmMapper;
import com.qg.wcsopcuaqj.business.params.TWcsTaksParam;
import com.qg.wcsopcuaqj.business.params.WcsRgvAlarmQueryParam;
import com.qg.wcsopcuaqj.business.service.ITWcsRgvAlarmService;
import com.qg.wcsopcuaqj.common.param.IdParam;
import com.qg.wcsopcuaqj.common.vo.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * <p>
 * wcs rgv 报警表 前端控制器
 * </p>
 *
 * @author caixiang
 * @since 2022-09-23
 */
@RestController
@RequestMapping("/business/t-wcs-rgv-alarm")
public class TWcsRgvAlarmController {
    @Autowired
    ITWcsRgvAlarmService service;

    @Autowired
    TWcsRgvAlarmMapper mapper;

    /**
     * 输入关键字后 点击查询按钮 查询
     * */
    @PostMapping(value = "findAll")
    @ApiOperation(value="依据条件查询 wcs alarm", notes="依据条件查询 wcs alarm")
    private R<IPage<TWcsRgvAlarm>> findAll(@RequestBody WcsRgvAlarmQueryParam queryParam) {
        IPage<TWcsRgvAlarm> all = mapper.findAll(new Page<TWcsRgvAlarm>(queryParam.getCurrent(), queryParam.getSize()),queryParam);
        return R.ok(all);
    }

    /**
     * ad
     * */
    @PostMapping(value = "create")
    @ApiOperation(value="用于wms 给 wcs 发任务用")
    private R<Integer> create(@RequestBody TWcsRgvAlarm tWcsTaksParam) {
        TWcsRgvAlarm tWcsRgvAlarm = new TWcsRgvAlarm();
        BeanUtils.copyProperties(tWcsTaksParam, tWcsRgvAlarm);
        int all = service.getBaseMapper().insert(tWcsRgvAlarm);
        return R.ok(all);
    }

    @PostMapping(value = "forMytest")
    @ApiOperation(value="用于wms 给 wcs 发任务用")
    private R<Integer> forMytest() {
        TWcsRgvAlarm alarm = new TWcsRgvAlarm();
        alarm.setAlarmInfo("网络断开连接，wcs与plc 出现异常");
        alarm.setIsTaskfinished(-1);
        alarm.setRgvName("-1");
        alarm.setIsSendfinished(-1);
        alarm.setHasGoods(-1);
        alarm.setIsPickfinished(-1);
        alarm.setCreateTime(LocalDateTime.now());
        alarm.setUpdateTime(LocalDateTime.now());
        service.getBaseMapper().insert(alarm);
        return R.ok(1);
    }





    /**
     * 逻辑删除
     * */
    @PostMapping(value = "findById")
    @ApiOperation(value="查找alarm，依据id")
    private R<TWcsRgvAlarm> findById(@RequestBody IdParam idParam) {
        return R.ok(service.getById(idParam.getId()));
    }
}
